
//背景滚动.
cc.Class({
    extends: cc.Component,

    properties: {
        bgNode1: cc.Node,
        bgNode2: cc.Node,
        cameraNode: cc.Node,
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        this.nextBgPos = this.bgNode2.getPositionY();
        this.moveBg = 1;
    },

    update (dt) {
        if(this.cameraNode.getPositionY() > this.nextBgPos){
            this.nextBgPos += this.bgNode1.height;
            if(this.moveBg == 1){
                this.bgNode1.setPosition(cc.v2(0,this.bgNode1.getPositionY() + this.bgNode1.height * 2));
                this.moveBg = 2;
            }
            else if(this.moveBg == 2){
                this.bgNode2.setPosition(cc.v2(0,this.bgNode2.getPositionY() + this.bgNode2.height * 2));
                this.moveBg = 1;
            }
        }
    },
});
